home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 March / CMCD0305.ISO / Software / Freeware / Programare / nvu / nvu-0.80-win32-installer-full.exe / {app} / chrome / toolkit.jar / content / global / globalOverlay.js < prev    next >
Text File  |  2004-05-17  |  5KB  |  193 lines

  1. function closeWindow(aClose)
  2. {
  3.   var windowCount = 0;
  4.   var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator);
  5.   var e = wm.getEnumerator(null);
  6.   
  7.   while (e.hasMoreElements()) {
  8.     var w = e.getNext();
  9.     ++windowCount;
  10.     if (windowCount == 2) 
  11.       break;
  12.   }
  13.  
  14.   // If we're down to the last window and someone tries to shut down, check to make sure we can!
  15.   if (windowCount == 1 && !canQuitApplication()) 
  16.     return false;
  17.  
  18.   if (aClose)    
  19.     window.close();
  20.   
  21.   return true;
  22. }
  23.  
  24. function canQuitApplication()
  25. {
  26.   var os = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
  27.   if (os) {
  28.     try {
  29.       var cancelQuit = Components.classes["@mozilla.org/supports-PRBool;1"].createInstance(Components.interfaces.nsISupportsPRBool);
  30.       os.notifyObservers(cancelQuit, "quit-application-requested", null);
  31.       
  32.       // Something aborted the quit process. 
  33.       if (cancelQuit.data)
  34.         return false;
  35.     }
  36.     catch (ex) {
  37.     }
  38.   }
  39.   return true;
  40. }
  41.  
  42. function goQuitApplication()
  43. {
  44.   if (!canQuitApplication())
  45.     return;
  46.     
  47.   var windowManager = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService();
  48.   var windowManagerInterface = windowManager.QueryInterface( Components.interfaces.nsIWindowMediator);
  49.   var enumerator = windowManagerInterface.getEnumerator( null );
  50.   var appShell = Components.classes['@mozilla.org/appshell/appShellService;1'].getService();
  51.   appShell = appShell.QueryInterface( Components.interfaces.nsIAppShellService );
  52.  
  53.   var nativeAppSupport = null;
  54.   try {
  55.     nativeAppSupport = appShell.nativeAppSupport;
  56.   }
  57.   catch ( ex ) {
  58.   }
  59.  
  60.   while ( enumerator.hasMoreElements()  )
  61.   {
  62.      var domWindow = enumerator.getNext();
  63.      if (("tryToClose" in domWindow) && !domWindow.tryToClose())
  64.        return false;          
  65.      domWindow.close();
  66.   };
  67.   appShell.quit(Components.interfaces.nsIAppShellService.eAttemptQuit);
  68.   return true;
  69. }
  70.  
  71. //
  72. // Command Updater functions
  73. //
  74. function goUpdateCommand(command)
  75. {
  76.   try {
  77.     var controller = top.document.commandDispatcher.getControllerForCommand(command);
  78.  
  79.     var enabled = false;
  80.  
  81.     if ( controller )
  82.       enabled = controller.isCommandEnabled(command);
  83.  
  84.     goSetCommandEnabled(command, enabled);
  85.   }
  86.   catch (e) {
  87.     dump("An error occurred updating the "+command+" command\n");
  88.   }
  89. }
  90.  
  91. function goDoCommand(command)
  92. {
  93.   try {
  94.     var controller = top.document.commandDispatcher.getControllerForCommand(command);
  95.     if ( controller && controller.isCommandEnabled(command))
  96.       controller.doCommand(command);
  97.   }
  98.   catch (e) {
  99.     dump("An error occurred executing the "+command+" command\n");
  100.     dump(e+"\n")
  101.   }
  102. }
  103.  
  104.  
  105. function goSetCommandEnabled(id, enabled)
  106. {
  107.   var node = document.getElementById(id);
  108.  
  109.   if ( node )
  110.   {
  111.     if ( enabled )
  112.       node.removeAttribute("disabled");
  113.     else
  114.       node.setAttribute('disabled', 'true');
  115.   }
  116. }
  117.  
  118. function goSetMenuValue(command, labelAttribute)
  119. {
  120.   var commandNode = top.document.getElementById(command);
  121.   if ( commandNode )
  122.   {
  123.     var label = commandNode.getAttribute(labelAttribute);
  124.     if ( label )
  125.       commandNode.setAttribute('label', label);
  126.   }
  127. }
  128.  
  129. function goSetAccessKey(command, valueAttribute)
  130. {
  131.   var commandNode = top.document.getElementById(command);
  132.   if ( commandNode )
  133.   {
  134.     var value = commandNode.getAttribute(valueAttribute);
  135.     if ( value )
  136.       commandNode.setAttribute('accesskey', value);
  137.   }
  138. }
  139.  
  140. // this function is used to inform all the controllers attached to a node that an event has occurred
  141. // (e.g. the tree controllers need to be informed of blur events so that they can change some of the
  142. // menu items back to their default values)
  143. function goOnEvent(node, event)
  144. {
  145.   var numControllers = node.controllers.getControllerCount();
  146.   var controller;
  147.  
  148.   for ( var controllerIndex = 0; controllerIndex < numControllers; controllerIndex++ )
  149.   {
  150.     controller = node.controllers.getControllerAt(controllerIndex);
  151.     if ( controller )
  152.       controller.onEvent(event);
  153.   }
  154. }
  155.  
  156. function visitLink(aEvent) {
  157.   var node = aEvent.target;
  158.   while (node.nodeType != Node.ELEMENT_NODE)
  159.     node = node.parentNode;
  160.   var url = node.getAttribute("link");
  161.   if (url != "")
  162.     top.opener.openNewWindowWith(url, null, false);
  163. }
  164.  
  165. function isValidLeftClick(aEvent, aName)
  166. {
  167.   return (aEvent.button == 0 && aEvent.originalTarget.localName == aName);
  168. }
  169.  
  170. function setTooltipText(aID, aTooltipText)
  171. {
  172.   var element = document.getElementById(aID);
  173.   if (element)
  174.     element.setAttribute("tooltiptext", aTooltipText);
  175. }
  176.  
  177. function FillInTooltip ( tipElement )
  178. {
  179.   var retVal = false;
  180.   var textNode = document.getElementById("TOOLTIP-tooltipText");
  181.   if (textNode) {
  182.     while (textNode.hasChildNodes())
  183.       textNode.removeChild(textNode.firstChild);
  184.     var tipText = tipElement.getAttribute("tooltiptext");
  185.     if (tipText) {
  186.       var node = document.createTextNode(tipText);
  187.       textNode.appendChild(node);
  188.       retVal = true;
  189.     }
  190.   }
  191.   return retVal;
  192. }
  193.